#include "DataGenerator.h"

#include "config.h"
#include "Utility.h"

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int getRandomIntValue(int range)
{     
    return rand()%range;
}

void generateRelation(char* name, bool printText)
{
    srand((unsigned)time(0));

    FILE* fileText = NULL;
    if (printText)  
        fileText = fopen(getFileNameByRelationNameWithExtension(name,"txt"),"w");

    FILE* fileBin = fopen(getFileNameByRelationNameWithExtension(name,"bin"),"wb");

    for(int i = 0; i < R_SIZE; i++)
    {

        if(printText) fprintf(fileText,"%d",i);

        fwrite(&i,sizeof(int),1,fileBin);
        for(int j = 1; j < ARITY; j++)
        {
            int tmp = getRandomIntValue(100);

            if(printText) fprintf(fileText," %d",tmp);

            fwrite(&tmp,sizeof(int),1,fileBin);      
        }
        if (printText) fprintf(fileText,"\n");
    }

    if (printText) fclose(fileText);

    fclose(fileBin);
}

